package com.woniuxy.threadmethods;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.LockSupport;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO: 查看java线程的状态
 * <P> Date: 2022/4/6:19:03
 * <P> Description:
 */
@Slf4j(topic = "c.TestState")
public class TestState {
    static Object object = new Object();

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            log.debug("running...");
        }, "t1");

        Thread t2 = new Thread(() -> {
            while (true) {

            }
        }, "t2");
        t2.start();

        Thread t3 = new Thread(() -> {
            log.debug("running...");
        }, "t3");
        t3.start();


        Thread t4 = new Thread(() -> {
            synchronized (TestState.class) {

                try {
                    Thread.sleep(100000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "t4");
        t4.start();

        Thread t5 = new Thread(() -> {
            try {
                //todo waiting
                t2.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t5");
        t5.start();


        Thread t6 = new Thread(() -> {
            synchronized (TestState.class) {
                //TODO blocked
                try {
                    Thread.sleep(100000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "t6");

        t6.start();

        Thread.sleep(500);
        //TODO NEW 新建
        log.debug("t1.state,{}", t1.getState());
        //TODO RUNNABLE 运行
        log.debug("t2.state,{}," ,t2.getState());
        //TODO TERMINATED 死亡
        log.debug("t3.stat,{},", t3.getState());

        //TODO TIMED_WAITING 有时间的等待
        log.debug("t4.state,{},", t4.getState());

        //TODO WAITING 等待
        log.debug("t5.state,{},", t5.getState());

        //TODO BLOCKED 阻塞
        log.debug("t6.state,{},", t6.getState());
    }
}

